// $ANTLR 3.4 C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g 2012-12-04 00:59:04

  package practica9;
  import java.util.Hashtable;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

@SuppressWarnings({"all", "warnings", "unchecked"})
public class XMLParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ABRIR_ANGULO", "ABRIR_ANGULO_FIN", "BLANCO", "CERRAR_ANGULO", "COMENTARIO", "DIGITO", "IDENT", "LETRA", "NUMERO", "TEXTO"
    };

    public static final int EOF=-1;
    public static final int ABRIR_ANGULO=4;
    public static final int ABRIR_ANGULO_FIN=5;
    public static final int BLANCO=6;
    public static final int CERRAR_ANGULO=7;
    public static final int COMENTARIO=8;
    public static final int DIGITO=9;
    public static final int IDENT=10;
    public static final int LETRA=11;
    public static final int NUMERO=12;
    public static final int TEXTO=13;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public XMLParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public XMLParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

    public String[] getTokenNames() { return XMLParser.tokenNames; }
    public String getGrammarFileName() { return "C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g"; }



        boolean cond_libro = false;
        boolean cond_autor = false;
        
        private ArrayList<RecognitionException> errors = new ArrayList<RecognitionException>();
        public ArrayList<RecognitionException> getErrors() {
           return errors;
        }
        @Override
        public void reportError (RecognitionException e) {
           String msg = getErrorMessage(e, getTokenNames());
           System.err.println(msg);
           errors.add(e);
        }



    // $ANTLR start "elementos"
    // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:37:1: elementos : ( elemento )* ;
    public final void elementos() throws RecognitionException {
        try {
            // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:37:11: ( ( elemento )* )
            // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:37:13: ( elemento )*
            {
            // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:37:13: ( elemento )*
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==ABRIR_ANGULO||LA1_0==COMENTARIO||LA1_0==TEXTO) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:37:14: elemento
            	    {
            	    pushFollow(FOLLOW_elemento_in_elementos63);
            	    elemento();

            	    state._fsp--;
            	    if (state.failed) return ;

            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);


            }

        }

        catch (RecognitionException e) {
        throw e;
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "elementos"



    // $ANTLR start "elemento"
    // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:39:1: elemento : (a= apertura elementos c= cierre | TEXTO | COMENTARIO );
    public final void elemento() throws RecognitionException {
        String a =null;

        String c =null;


        try {
            // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:39:9: (a= apertura elementos c= cierre | TEXTO | COMENTARIO )
            int alt2=3;
            switch ( input.LA(1) ) {
            case ABRIR_ANGULO:
                {
                alt2=1;
                }
                break;
            case TEXTO:
                {
                alt2=2;
                }
                break;
            case COMENTARIO:
                {
                alt2=3;
                }
                break;
            default:
                if (state.backtracking>0) {state.failed=true; return ;}
                NoViableAltException nvae =
                    new NoViableAltException("", 2, 0, input);

                throw nvae;

            }

            switch (alt2) {
                case 1 :
                    // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:39:11: a= apertura elementos c= cierre
                    {
                    pushFollow(FOLLOW_apertura_in_elemento74);
                    a=apertura();

                    state._fsp--;
                    if (state.failed) return ;

                    if ( state.backtracking==0 ) {if (a.compareTo("libro") == 0)
                                             cond_libro = true;
                                          else if (a.compareTo("autor") == 0) {
                                             if (cond_libro)
                                                cond_autor = true;
                                             else {
                                                System.err.println("ERROR: El tag: <" + a + "> se encuentra fuera de un libro.");
                                                throw new RecognitionException();
                                             }
                                          }
                                          }

                    pushFollow(FOLLOW_elementos_in_elemento113);
                    elementos();

                    state._fsp--;
                    if (state.failed) return ;

                    pushFollow(FOLLOW_cierre_in_elemento138);
                    c=cierre();

                    state._fsp--;
                    if (state.failed) return ;

                    if ( state.backtracking==0 ) {if (a.compareTo(c) != 0) {
                                           System.err.println("ERROR: El tag de apertura: <" + a + "> no coincide con el tag de cierre: </" + c + ">");
                                           throw new RecognitionException();
                                        }
                                        
                                        if (a.compareTo("libro") == 0) {
                                           if (cond_libro && !cond_autor) {
                                              System.err.println("ERROR: Debe incluirse el tag <autor> dentro del bloque libro.");
                                              throw new RecognitionException();
                                           }
                                           cond_libro = false;
                                           cond_autor = false;
                                        }
                                        }

                    }
                    break;
                case 2 :
                    // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:68:11: TEXTO
                    {
                    match(input,TEXTO,FOLLOW_TEXTO_in_elemento164); if (state.failed) return ;

                    }
                    break;
                case 3 :
                    // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:70:11: COMENTARIO
                    {
                    match(input,COMENTARIO,FOLLOW_COMENTARIO_in_elemento188); if (state.failed) return ;

                    }
                    break;

            }
        }
        catch (RecognitionException ex) {
            throw ex;
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "elemento"



    // $ANTLR start "apertura"
    // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:73:1: apertura returns [String id = \"\"] : ABRIR_ANGULO i= IDENT CERRAR_ANGULO ;
    public final String apertura() throws RecognitionException {
        String id =  "";


        Token i=null;

        try {
            // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:73:34: ( ABRIR_ANGULO i= IDENT CERRAR_ANGULO )
            // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:73:36: ABRIR_ANGULO i= IDENT CERRAR_ANGULO
            {
            match(input,ABRIR_ANGULO,FOLLOW_ABRIR_ANGULO_in_apertura205); if (state.failed) return id;

            i=(Token)match(input,IDENT,FOLLOW_IDENT_in_apertura209); if (state.failed) return id;

            match(input,CERRAR_ANGULO,FOLLOW_CERRAR_ANGULO_in_apertura211); if (state.failed) return id;

            if ( state.backtracking==0 ) {id += i.getText();}

            }

        }

        catch (RecognitionException e) {
        throw e;
        }

        finally {
        	// do for sure before leaving
        }
        return id;
    }
    // $ANTLR end "apertura"



    // $ANTLR start "cierre"
    // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:75:1: cierre returns [String id = \"\"] : ABRIR_ANGULO_FIN i= IDENT CERRAR_ANGULO ;
    public final String cierre() throws RecognitionException {
        String id =  "";


        Token i=null;

        try {
            // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:75:32: ( ABRIR_ANGULO_FIN i= IDENT CERRAR_ANGULO )
            // C:\\Users\\usuario\\workspace\\Practica9-PL\\src\\main\\java\\practica9\\XMLParser.g:75:34: ABRIR_ANGULO_FIN i= IDENT CERRAR_ANGULO
            {
            match(input,ABRIR_ANGULO_FIN,FOLLOW_ABRIR_ANGULO_FIN_in_cierre224); if (state.failed) return id;

            i=(Token)match(input,IDENT,FOLLOW_IDENT_in_cierre228); if (state.failed) return id;

            match(input,CERRAR_ANGULO,FOLLOW_CERRAR_ANGULO_in_cierre230); if (state.failed) return id;

            if ( state.backtracking==0 ) {id += i.getText();}

            }

        }

        catch (RecognitionException e) {
        throw e;
        }

        finally {
        	// do for sure before leaving
        }
        return id;
    }
    // $ANTLR end "cierre"

    // Delegated rules


 

    public static final BitSet FOLLOW_elemento_in_elementos63 = new BitSet(new long[]{0x0000000000002112L});
    public static final BitSet FOLLOW_apertura_in_elemento74 = new BitSet(new long[]{0x0000000000002130L});
    public static final BitSet FOLLOW_elementos_in_elemento113 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_cierre_in_elemento138 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_TEXTO_in_elemento164 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_COMENTARIO_in_elemento188 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ABRIR_ANGULO_in_apertura205 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_IDENT_in_apertura209 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_CERRAR_ANGULO_in_apertura211 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ABRIR_ANGULO_FIN_in_cierre224 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_IDENT_in_cierre228 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_CERRAR_ANGULO_in_cierre230 = new BitSet(new long[]{0x0000000000000002L});

}